﻿using System.Collections.Generic;
using System.Configuration;

namespace DIX.Configuration
{
    public class DIXObjectsCollection : ConfigurationElementCollection
    {
        #region INDEXER
        
        public DIXAddElement this[int index]
        {
            get
            {
                return base.BaseGet(index) as DIXAddElement;
            }
            set
            {
                if (base.BaseGet(index) != null)
                    base.BaseRemove(index);

                base.BaseAdd(index, value);
            }
        }

        #endregion

        #region METHODS
        
        public List<DIXAddElement> GetDIXAddElementList()
        {
            var result = new List<DIXAddElement>();

            foreach (var item in this)
            {
                result.Add(item);
            }

            return result;
        }

        public new  IEnumerator<DIXAddElement> GetEnumerator()
        {
            var iterator = base.GetEnumerator();

            while (iterator.MoveNext())
            {
                yield return (DIXAddElement)iterator.Current;
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new DIXAddElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((DIXAddElement)element).Name;
        }

        #endregion
    }
}
